<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      ~(function () {
        /*
                     async 可配合promise进行异步请求同步操作
                async await 是异步的             
            */
        //先输出2在输出1
        async function fn() {
          await 10;
          console.log(1);
        }
        fn();
        console.log(2);
      })();

      ~(function () {
        /*
因generator需要手动一步一步操作较为麻烦       
            */
        //先输出2在输出1
        async function Async() {
          let a1 = await read('a');
          let a2 = await read('b');
          let a3 = await read('c');
          console.log(a1.toString());
          console.log(a2.toString());
          console.log(a3.toString());
        }
        Async();
      })();

      ~(function () {
        async function Async() {
          let a1;
          let a2;
          let a3;
          try {
            a1 = await read('a');
            a2 = await read('b');
            a3 = await read('c');
          } catch (e) {
            //TODO handle the exception
          }
          console.log(a1);
          console.log(a2);
          console.log(a3);
        }
        Async();
      })();
    </script>
  </body>
</html>
